package ext.tianma.part.util;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

import com.infoengine.SAK.Task;
import com.infoengine.object.IeObject;
import com.infoengine.object.factory.Group;
import com.infoengine.util.IEException;

import wt.part.WTPart;

public class ClassificationUtil {
	private final static String PATH = "/ext/tianma/util/queryClassificationPath.xml";
	
	
	/**
	 * 查询对象的分类结点的全路径
	 * @param obj
	 * @return
	 */
	public static String queryClassificationPath(Object obj){
		String classificationPath = "";
		if(obj != null){
			if(obj instanceof WTPart){
				WTPart part = ( WTPart ) obj ;
				Task task = new Task(PATH);
				task.addParam("WHERE", "number='" + part.getNumber() + "'");
				try {
					task.invoke();
					IeObject ieoRecord = null;
					Group group = task.getGroup("part");
					
					/**
					 * 转换为xml格式输出
					 * PrintWriter pw = new PrintWriter(System.out);
					 * group.toXML(pw, true, true);
					 */

					System.out.println("groupCount:" + group.getElementCount());
					for (Enumeration enum1 = group.getGroup().getChildren(); enum1
							.hasMoreElements();) {
						ieoRecord = (IeObject) enum1.nextElement();
						classificationPath = ieoRecord.getAtt("classification")
								.getDatum().toString();
						System.out.println("物料的"
								+ ",number:" + part.getNumber() + ",classification:"
								+ classificationPath );
					}
				} catch (IEException e) {
					e.printStackTrace();
				} catch (IOException e) {
					e.printStackTrace();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		return classificationPath;
		
	}
	
}
